package com.ujiuye.model;

import java.util.List;

public class Page<T> {
    //每页显示数据的条数，默认3
    private Integer initSize = 3;
    //设置当前页，默认1
    private Integer currentPage = 1;
    //总共有多少数据
    private Integer countNum;
    //总共有多少页
    private Integer countPage;
    //上一页
    private Integer prePage;
    //下一页
    private Integer nextPage;
    //存放页面数据的容器
    private List<T> pageList;

    public Page(Integer initSize, Integer currentPage, Integer countNum, List<T> pageList) {
        this.initSize = initSize;
        this.currentPage = currentPage;
        this.countNum = countNum;
        this.pageList = pageList;
        //对总页码的处理
        int num = this.countNum / this.initSize;
        //余数等于0 则总页面等于商，否则为商1
        this.countPage =  this.countNum % this.initSize == 0 ? num : num+1;
        //上一页，如果当前页大于1,则下一页为当前页减1,否则就为1
        this.prePage = this.currentPage > 1 ? this.currentPage-1 : 1;
        //下一页，如果当前页小于总页码，下一页为当前页加1,否则为总页码
        this.nextPage = this.currentPage < this.countPage ? this.currentPage+1 : this.countPage;

    }
    public Page(Integer initSize, Integer currentPage, Integer countNum) {
        this.initSize = initSize;
        this.currentPage = currentPage;
        this.countNum = countNum;
        // 对总页码的处理
        int num = this.countNum / this.initSize;
        // 余数等于0 则总页面等于商,否则为商加1
        this.countPage = this.countNum % this.initSize == 0 ? num : num + 1;
        // 前一页,如果当前页大于1 ,则下一页为当前页减1,否则就为 1
        this.prePage = this.currentPage > 1 ? this.currentPage - 1 : 1;
        // 如果当前页小于总页码,下一页为当前页加1,否则为总页码
        this.nextPage = this.currentPage < this.countPage ? this.currentPage + 1 : this.countPage;
    }

    public Integer getInitSize() {
        return initSize;
    }

    public void setInitSize(Integer initSize) {
        this.initSize = initSize;
    }

    public Integer getCurrentPage() {
        return currentPage;
    }

    public void setCurrentPage(Integer currentPage) {
        this.currentPage = currentPage;
    }

    public Integer getCountNum() {
        return countNum;
    }

    public void setCountNum(Integer countNum) {
        this.countNum = countNum;
    }

    public Integer getCountPage() {
        return countPage;
    }

    public void setCountPage(Integer countPage) {
        this.countPage = countPage;
    }

    public Integer getPrePage() {
        return prePage;
    }

    public void setPrePage(Integer prePage) {
        this.prePage = prePage;
    }

    public Integer getNextPage() {
        return nextPage;
    }

    public void setNextPage(Integer nextPage) {
        this.nextPage = nextPage;
    }

    public List<T> getPageList() {
        return pageList;
    }

    public void setPageList(List<T> pageList) {
        this.pageList = pageList;
    }
}
